﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Main : ATPages
{
    ZSql info = new ZSql();
    ZSql menu = new ZSql();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitMenu();

            lblUser.Text = Server.UrlDecode(Request.Cookies["user"].Values["name"]);

            lblDept.Text = info.GetScalar("select deptname from department where deptid = " + Request.Cookies["user"].Values["deptid"]).ToString();
        }
    }

    //初始化菜单数据
    private void InitMenu()
    {
        DataTable menu = GetMenu();

        MenuClass.MenuNew(MenuData, null, menu, "menu", "parentid", "menuid", "url", "data");
    }


    //根据权限得到菜单数据
    private DataTable GetMenu()
    {
        string sql = "select * from menu where 1=1";

        if (Server.UrlDecode(Request.Cookies["user"].Values["roleid"]) != "1")
        {
            string menuid = "0";

            info.Open("select permission from purview where roleid = " + Request.Cookies["user"].Values["roleid"] + " or userid = '" + Request.Cookies["user"].Values["id"] + "'");
            for (int i = 0; i < info.m_table.Rows.Count; i++)
            {
                menuid += "," + info.m_table.Rows[i]["permission"].ToString();
            }

            sql += " and menuid in (" + menuid + ")";
        }

        menu.Open(sql);

        DataTable dt = menu.m_table;
        menu.Close();

        return dt;
    }
}
